#include<iostream>
#include<cstdio>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
using namespace std;


extern char** environ;
int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //子进程
    char *const argv[] = {
            (char*)"other",
            nullptr
        };

        //(void)argv;
        char *const env[] = {
            (char*)"HELLO=bite",
            (char*)"HELLO1=bite1",
            (char*)"HELLO2=bite2",
            (char*)"HELLO3=bite3"
        };

    execvpe("./other", argv, env);
    //execl("/bin/ls","ls","-l","--color","-a",nullptr);
    //execl("/usr/bin/python","python","test.py",nullptr);
    execl("/usr/bin/bash","bash","test.sh",nullptr);
    exit(1);  
  }
  else{
    //父进程
    pid_t rid=waitpid(id,nullptr,0);
    if(rid>0)
    {
      printf("等待子进程成功\n");
    }
  }

  
  //printf("我是myexec,我的pid:%d\n",getpid());
  //execl("./other","other",nullptr);
  
  //int n=execl("/bin/ls","ls","-l","--color","-a",nullptr);
  //printf("execl return val:%d\n",n);
 // execl("/usr/bin/top","top",nullptr);
  return 0;
}
